<template>
  <view class="cashgift_pop_box">
    <unipopup ref="unipopup" type="center" :show="showPop" class="cashgift_pop">
      <text class="close_icon iconfont icon-guanbi" @click="close"></text>
      <view class="cashgift_content">
        <view class="title">匹配订单</view>
        <form @submit="submit" :report-submit="true">
          <view class="form_item">
            <text class="label">订单号：</text>
            <view class="text">
              <input type="digit" readonly class="input" v-model="submitForm.tradeParentId" placeholder="确认收货后的订单编号" />
            </view>
          </view>
          <view class="btn_group">
            <button class="btn cancel" @click="close">取消</button>
            <button class="btn submit" form-type="submit">绑定</button>
          </view>
        </form>
      </view>
    </unipopup>
  </view>
</template>

<script>
  import CONFIG from '@/config/config.conf'
  import unipopup from "@/pages/pagecomponents/uni/uni-popup.vue"
  export default {
    components: {
      unipopup
    },
    props: {},
    data() {
      return {
        submitForm: {
          tradeParentId: '', // 确认收货后的订单编号
        },
        showPop: false,
      }
    },
    created() {},
    methods: {
      submit(e) {
        let formId = e.detail.formId // formId，用于发送模板消息
        // 提交表单
        let submitForm = this.submitForm
        let hasNull = false;
        Object.keys(submitForm).some(item => {
          if (!submitForm[item] || submitForm[item] === '') {
            hasNull = true;
            return true;
          }
        })
        if (hasNull) {
          this.$refs.unipopup.shake(); // 模态框抖动
          uni.showToast({
            icon: 'none',
            title: '对不起，请将表单填写完整后提交'
          });
          return;
        }
        this.$api.user.settleOrder({
          ...submitForm,
          page: '/pagesusercenter/order/index',
          formId: formId,
        }).then(res => { // 新增订单
          uni.showModal({
            showCancel: false,
            confirmText: '我知道了',
            title: '成功',
            content: `订单匹配成功，本次获得积分+${res.data.addGold}`,
            success: res => {}
          });
          this.close();
        })
      },
      close() {
        this.showPop = false
      },
      show() {
        this.showPop = true
      },
    }
  }
</script>

<style scoped lang="scss">
  .cashgift_pop_box {
    .cashgift_pop {
      .close_icon {
        position: absolute;
        top: 20upx;
        right: 20upx;
        font-size: 50upx;
      }
      .cashgift_content {
        padding: 50upx 0 0;
        width: 650upx;
        border-radius: 20upx;
        background-color: #ffffff;
        .title {
          text-align: center;
          padding: 0 50upx 50upx;
          color: #294d7d;
          font-size: 40upx;
          font-weight: 600;
        }
        .form_item {
          padding: 0 30upx;
          line-height: 70upx;
          font-size: 30upx;
          .label {
            display: inline-block;
            width: 150upx;
            height: 70upx;
            vertical-align: middle;
          }
          .text {
            display: inline-block;
            width: 400upx;
            height: 70upx;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
            vertical-align: middle;
            .input {
              height: 70upx;
              line-height: 70upx;
              border-bottom: 1px solid #C8C8C8;
            }
          }
        }
        .btn_group {
          height: 100upx;
          margin-top: 50upx;
          .btn {
            height: 100upx;
            display: inline-block;
            width: 50%;
            background: white;
          }
          .submit {
            color: white;
            background: #294d7d;
          }
        }
      }
    }
  }
</style>
